import React from 'react'
import { Layout} from 'antd';
import Table from '../Table'
import Editor from "../Editor"
import {useSelector,useDispatch,connect} from 'react-redux'
import "./tr.css"

const {Content} = Layout;



const Usercoms = () => {

    const userList = useSelector(state=> state.user.userList)
    const valueList = useSelector(state=> state.value.valueList)
    const dispatch = useDispatch()
  let value;
  
  const columns = [
    {
      title: 'key值',
      key: 'key0',
      dataIndex: 'key0',
      valueType: 'text'
    },
    {
        title: '用户名',
        dataIndex: 'username',
        key: 'username',
        ellipsis:true
    },
    {
        title: '用户头像',
        key: 'userimg',
        dataIndex: 'userimg',
        valueType: 'avatar',
        hideInSearch: true
    },
    {
        title: '内容',
        key: 'content',
        dataIndex: 'content',
        valueType: 'text'
    },
    {
        title: '时间',
        key: 'time0',
        dataIndex: 'time0',
        valueType: 'text'
    },
    {
        title: '操作',
        key: 'option',
        width: 120,
        valueType: 'option',
        render: (text,record,index,action) => [<div onClick={()=>{
          dispatch({type:'get',con:record});
        }}><Editor ques={user} url="http://101.34.58.111:8081/usercoms"/></div>
        , <a onClick={async ()=>{
          await fetch(`http://101.34.58.111:8081/usercoms/${record.key0}`,{
          method:'delete',
          headers: {
            'Content-Type': 'application/json;charset=UTF-8'
          },
          body:JSON.stringify(record)
        })
        dispatch({type:'delete',content:['delete']})
        }}>删除</a>]
      }];
const right = {
}

  const user = [
    {name:'key0',label:'key值',tooltip:'最长为24位',placeholder:'请输入key值'},
    {name:'username',label:'用户名',tooltip:'最长为24位',placeholder:'请输入用户名称'},
    {name:'userimg',label:'用户头像',placeholder:'上传头像'},
    {name:'content',label:'内容',tooltip:'最长为24位',placeholder:'请输入内容'},
    {name:'time0',label:'时间',tooltip:'最长为24位',placeholder:'请输入时间'}
]

    return (
        <Content className="site-layout-background" style={{paddingLeft: 10,margin: 0,minHeight: 280,}}>
          <Table title="圈子评论管理" columns={columns} right={right} url="http://101.34.58.111:8081/usercoms" ques={user} />
        </Content>
    )
}

export default connect()(Usercoms)